/*
 * Copyright 2012 Faculty of Informatics - Masaryk University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.pa165.creatures.dto.web.mapping;

import cz.muni.fi.pa165.creatures.dto.mapping.api.MappingDTO;
import cz.muni.fi.pa165.creatures.dto.web.FunctionDTO;
import cz.muni.fi.pa165.creatures.model.web.Function;

/**
 * This class represents the mapping between
 * {@link cz.muni.fi.pa165.creatures.model.web.Function} and
 * {@link cz.muni.fi.pa165.creatures.dto.web.FunctionDTO} and vice versa.
 *
 * @author smikloso
 */
public class FunctionMapping implements MappingDTO<FunctionDTO, Function> {

    @Override
    public FunctionDTO entityToDTO(Function entity) {
        if (entity == null) {
            return null;
        }
        FunctionDTO dto = new FunctionDTO();
        if (entity.getId() != null) {
            dto.setId(Long.toString(entity.getId()));
        }
        if (entity.getName() != null) {
            dto.setName(entity.getName());
        }
        return dto;
    }

    @Override
    public Function DTOtoEntity(FunctionDTO dto) {
        if (dto == null) {
            return null;
        }
        Function entity = new Function();
        if (dto.getId() != null) {
            entity.setId(Long.parseLong(dto.getId()));
        }
        if (dto.getName() != null) {
            entity.setName(dto.getName());
        }
        return entity;
    }
}
